home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / listbox / listtab / listdemo.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-11-27  |  8.5 KB  |  241 lines

  1. VERSION 4.00
  2. Begin VB.Form frmListDemo 
  3.    Appearance      =   0  'Flat
  4.    BackColor       =   &H80000005&
  5.    Caption         =   "List Control Demo"
  6.    ClientHeight    =   4800
  7.    ClientLeft      =   2280
  8.    ClientTop       =   1650
  9.    ClientWidth     =   5760
  10.    BeginProperty Font 
  11.       name            =   "MS Sans Serif"
  12.       charset         =   1
  13.       weight          =   700
  14.       size            =   8.25
  15.       underline       =   0   'False
  16.       italic          =   0   'False
  17.       strikethrough   =   0   'False
  18.    EndProperty
  19.    ForeColor       =   &H80000008&
  20.    Height          =   5205
  21.    Left            =   2220
  22.    LinkTopic       =   "Form1"
  23.    ScaleHeight     =   4800
  24.    ScaleWidth      =   5760
  25.    Top             =   1305
  26.    Width           =   5880
  27.    Begin VB.TextBox txtSearch 
  28.       Appearance      =   0  'Flat
  29.       Height          =   285
  30.       Left            =   240
  31.       TabIndex        =   1
  32.       Top             =   360
  33.       Width           =   5295
  34.    End
  35.    Begin VB.CommandButton cmdExit 
  36.       Appearance      =   0  'Flat
  37.       BackColor       =   &H80000005&
  38.       Caption         =   "E&xit"
  39.       Height          =   495
  40.       Left            =   3000
  41.       TabIndex        =   8
  42.       Top             =   4080
  43.       Width           =   2535
  44.    End
  45.    Begin VB.ListBox lstFonts 
  46.       Appearance      =   0  'Flat
  47.       Height          =   1200
  48.       Left            =   240
  49.       Sorted          =   -1  'True
  50.       TabIndex        =   6
  51.       Top             =   3360
  52.       Width           =   2535
  53.    End
  54.    Begin VB.TextBox txtListHeadings 
  55.       Appearance      =   0  'Flat
  56.       BorderStyle     =   0  'None
  57.       Enabled         =   0   'False
  58.       ForeColor       =   &H00C00000&
  59.       Height          =   255
  60.       Left            =   240
  61.       MultiLine       =   -1  'True
  62.       TabIndex        =   4
  63.       Text            =   "LISTDEMO.frx":0000
  64.       Top             =   1440
  65.       Width           =   855
  66.    End
  67.    Begin VB.CommandButton cmdSetColumns 
  68.       Appearance      =   0  'Flat
  69.       BackColor       =   &H80000005&
  70.       Caption         =   "(set columns)"
  71.       Height          =   495
  72.       Left            =   3000
  73.       TabIndex        =   7
  74.       Top             =   3480
  75.       Width           =   2535
  76.    End
  77.    Begin VB.ListBox lstFruits 
  78.       Appearance      =   0  'Flat
  79.       BeginProperty Font 
  80.          name            =   "MS Sans Serif"
  81.          charset         =   1
  82.          weight          =   700
  83.          size            =   9.75
  84.          underline       =   0   'False
  85.          italic          =   0   'False
  86.          strikethrough   =   0   'False
  87.       EndProperty
  88.       Height          =   1230
  89.       Left            =   240
  90.       Sorted          =   -1  'True
  91.       TabIndex        =   5
  92.       Top             =   1800
  93.       Width           =   5295
  94.    End
  95.    Begin VB.ComboBox cboSelect 
  96.       Appearance      =   0  'Flat
  97.       Height          =   300
  98.       Left            =   240
  99.       Sorted          =   -1  'True
  100.       Style           =   2  'Dropdown List
  101.       TabIndex        =   3
  102.       Top             =   1080
  103.       Width           =   5295
  104.    End
  105.    Begin VB.Label lblSearch 
  106.       Appearance      =   0  'Flat
  107.       BackColor       =   &H80000005&
  108.       Caption         =   "Search:"
  109.       ForeColor       =   &H80000008&
  110.       Height          =   255
  111.       Left            =   240
  112.       TabIndex        =   0
  113.       Top             =   120
  114.       Width           =   1455
  115.    End
  116.    Begin VB.Label lblSelect 
  117.       Appearance      =   0  'Flat
  118.       BackColor       =   &H80000005&
  119.       Caption         =   "Select:"
  120.       ForeColor       =   &H80000008&
  121.       Height          =   255
  122.       Left            =   240
  123.       TabIndex        =   2
  124.       Top             =   840
  125.       Width           =   1455
  126.    End
  127. Attribute VB_Name = "frmListDemo"
  128. Attribute VB_Creatable = False
  129. Attribute VB_Exposed = False
  130. Option Explicit
  131. 'Updated 01/06/95 - DULIST.BAS Fixes and Enhancements
  132. '                   dulist_tfSetListCols
  133. '                   --------------------
  134. '                   Fixed bug that caused an endless
  135. '                   loop if the last character of a
  136. '                   listbox item string was a Chr$(9) tab.
  137. '                   dulist_sGetColumn
  138. '                   -----------------
  139. '                   New routine to extract data, by column,
  140. '                   from a tab-delimited string.
  141. '                   dulist_AddHorizScrollBar
  142. '                   ------------------------
  143. '                   New routine to add a horizontal
  144. '                   scrollbar to a listbox.
  145. 'If you have questions, comments, or suggestions for
  146. 'improving the code presented here, please forward them
  147. 'to me; your input is welcome:
  148. '        Brad Kaenel
  149. '        PC HELP-LINE
  150. '        35250 Silver Leaf Circle
  151. '        Yucaipa, CA  92399
  152. '        United States
  153. '        CIS: 72357,3523
  154. '        Internet: 72357.3523@compuserve.com
  155. 'Although multi-column listboxes are a common
  156. 'requirement, they are difficult to accomplish
  157. 'in VB.
  158. 'A simple solution is to select a mono-spaced
  159. 'font for the listbox and align the data manually,
  160. 'but this is not always visually appealing.  However,
  161. 'with a little more work you can set dynamic tabstops
  162. 'that will work with proportional fonts.
  163. 'This sample demonstrates how to set tabstops in a listbox,
  164. 'using a borderless, disabled text box for the column
  165. 'headings.  It also shows how to "pre-select" a listbox
  166. 'or combobox item, using Windows API functions.
  167. Dim sFruit(10) As String, sMyFruit As String
  168. Dim nTabStopsSet As Integer
  169. Private Sub cboSelect_Click()
  170. sMyFruit = cboSelect.Text
  171. txtSearch.Text = sMyFruit  'synchronize the textbox
  172. Call SelectFruit           'synchronize the listbox
  173. End Sub
  174. Private Sub cmdExit_Click()
  175. Unload frmListDemo
  176. End Sub
  177. Private Sub cmdSetColumns_Click()
  178. Call SetTabStops
  179. End Sub
  180. Private Sub Form_Load()
  181. Dim nFruitCount As Integer
  182. Dim sTAB As String
  183. sTAB = Chr$(9)
  184. 'add a horiz scrollbar
  185. Call dulist_AddHorizScrollBar(lstFruits, 0)
  186. 'load up some multi-column data
  187. txtListHeadings.Text = "Fruit" + sTAB + "Opinion" + sTAB + "Color"
  188. sFruit(1) = "Oranges" + sTAB + "Good" + sTAB + "Orange, of course"
  189. sFruit(2) = "Bananas" + sTAB + "Munchy" + sTAB + "Yellow"
  190. sFruit(3) = "Apples" + sTAB + "Delicious" + sTAB + "Red"
  191. sFruit(4) = "Blueberries" + sTAB + "Nah" + sTAB + "Blue"
  192. sFruit(5) = "Plums" + sTAB + "Better than prunes" + sTAB + "Purple"
  193. sFruit(6) = "Watermelons" + sTAB + "Marvelous" + sTAB + "Red and Green"
  194. sFruit(7) = "Cherries" + sTAB + "Ummm..." + sTAB + "Bright Red"
  195. sFruit(8) = "Mangos" + sTAB + "Juicy" + sTAB + "No idea"
  196. sFruit(9) = "Kiwis" + sTAB + "Kinda weird" + sTAB + "Fuzzy Green"
  197. sFruit(10) = "Peaches" + sTAB + "OK" + sTAB + "Peach, I guess(?)"
  198. For nFruitCount = 1 To UBound(sFruit)
  199.    lstFruits.AddItem sFruit(nFruitCount)
  200.    'comboboxes don't support tabstops, so use only the first column string
  201.    cboSelect.AddItem dulist_sGetColumn(sFruit(nFruitCount), 1)
  202. For nFruitCount = 0 To Screen.FontCount - 1
  203.    lstFonts.AddItem Screen.Fonts(nFruitCount)
  204. nTabStopsSet = True
  205. cmdSetColumns.Value = True  'trigger tab stops
  206. End Sub
  207. Private Sub lstFonts_Click()
  208. lstFruits.FontName = lstFonts.List(lstFonts.ListIndex)
  209. lstFruits.Height = (lstFonts.Top - lstFruits.Top) - 20
  210. nTabStopsSet = Not nTabStopsSet
  211. cmdSetColumns.Value = True  'trigger tab stops
  212. End Sub
  213. Private Sub lstFruits_Click()
  214. sMyFruit = dulist_sGetColumn((lstFruits.List(lstFruits.ListIndex)), 1)
  215. txtSearch.Text = sMyFruit  'synchronize the textbox
  216. Call SelectFruit           'synchronize the combobox
  217. End Sub
  218. Private Sub SelectFruit()
  219. If dulist_tfSelectListItem(lstFruits, sMyFruit) Then
  220.    If dulist_tfSelectListItem(cboSelect, sMyFruit) Then
  221.    End If
  222. End If
  223. End Sub
  224. Private Sub SetTabStops()
  225. If nTabStopsSet Then
  226.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, True) Then
  227.       cmdSetColumns.Caption = "Set &Custom Tab Stops"
  228.       nTabStopsSet = Not nTabStopsSet
  229.    End If
  230.    If dulist_tfSetListCols(lstFruits, txtListHeadings, False, False) Then
  231.       cmdSetColumns.Caption = "Reset &Default Tab Stops"
  232.       nTabStopsSet = Not nTabStopsSet
  233.    End If
  234. End If
  235. End Sub
  236. Private Sub txtSearch_Change()
  237. sMyFruit = txtSearch.Text
  238. Call SelectFruit           'synchronize the listbox
  239.                            'and the combobox
  240. End Sub
  241.